package com.atguigu.democustomer230301.service.impl;

import com.atguigu.democustomer230301.bean.User;
import com.atguigu.democustomer230301.mapper.UserMapper;
import com.atguigu.democustomer230301.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String sayJi() {
        System.out.println("Service:111111");
        return "Hello SZ";
    }

    @Override
    public String getUserByName(String name) {
        User user = userMapper.selectUserByName(name);
        return "User:" + user.toString();
    }

    @Override
    public String getUserById(String id) {
        User user = userMapper.selectById(id);
        return "User:" + user;
    }

    @Override
    public String getAllUser() {
        return "User:" + userMapper.selectList(null);
    }

    @Override
    public void updateById(Integer id, String name, Integer age) {
        userMapper.updateById(id, name, age);
        System.out.println("Service:" + id + name + age);
    }

    @Override
    public void insertUser(User user) {
        userMapper.insert(user);
        System.out.println("Service:" + user);
    }

//    删除一条数据
    @Override
    public void deleteUserById(Integer id) {
        userMapper.deleteById(id);
        System.out.println("Service:" + id);
    }
}
